package com.ruoyi.gis.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.gis.componets.RasterDatasetComponent;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gis.domain.DatasetRaster;
import com.ruoyi.gis.service.IDatasetRasterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 栅格数据Controller
 * 
 * @author rww
 * @date 2024-08-30
 */
@RestController
@RequestMapping("/earthai/raster")
public class DatasetRasterController extends BaseController
{
    @Autowired
    private IDatasetRasterService datasetRasterService;
    @Autowired
    private RasterDatasetComponent rasterDatasetComponent;
    /**
     * 查询栅格数据列表
     */
    @PreAuthorize("@ss.hasPermi('earthai:raster:list')")
    @GetMapping("/list")
    public TableDataInfo list(DatasetRaster datasetRaster)
    {
        startPage();
        List<DatasetRaster> list = datasetRasterService.selectDatasetRasterList(datasetRaster);
        return getDataTable(list);
    }

    /**
     * 导出栅格数据列表
     */
    @PreAuthorize("@ss.hasPermi('earthai:raster:export')")
    @Log(title = "栅格数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DatasetRaster datasetRaster)
    {
        List<DatasetRaster> list = datasetRasterService.selectDatasetRasterList(datasetRaster);
        ExcelUtil<DatasetRaster> util = new ExcelUtil<DatasetRaster>(DatasetRaster.class);
        util.exportExcel(response, list, "栅格数据数据");
    }

    /**
     * 获取栅格数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('earthai:raster:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(datasetRasterService.selectDatasetRasterById(id));
    }

    /**
     * 新增栅格数据
     */
    @PreAuthorize("@ss.hasPermi('earthai:raster:add')")
    @Log(title = "栅格数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DatasetRaster datasetRaster)
    {
        return toAjax(datasetRasterService.insertDatasetRaster(datasetRaster));
    }

    /**
     * 修改栅格数据
     */
    @PreAuthorize("@ss.hasPermi('earthai:raster:edit')")
    @Log(title = "栅格数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DatasetRaster datasetRaster)
    {
        return toAjax(datasetRasterService.updateDatasetRaster(datasetRaster));
    }

    /**
     * 删除栅格数据
     */
    @PreAuthorize("@ss.hasPermi('earthai:raster:remove')")
    @Log(title = "栅格数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(datasetRasterService.deleteDatasetRasterByIds(ids));
    }

    @PostMapping("publish/raster/{dataRasterId}")
    public AjaxResult publishFile(HttpServletRequest request,
                                  @PathVariable Long dataRasterId) {
        rasterDatasetComponent.sendRasterDataPublishLayerMessage(dataRasterId);
        return AjaxResult.success();
    }
}
